********************************************************************************
*************************** Do File (2): Table 1 *******************************
********************************************************************************

clear
set more off

use "$data/EPH_1015_format.dta", clear

destring occupation occupation_unemp occup_all, replace

*** Keep only observations that have all controls used

keep if (occupation !=. & underemp != . & cont_pens !=. & domwk_all !=. & linc_mjob_base08 !=. & lwagehr_mjob_base08 !=. & linc_total_base08 != . & lhours_mjob !=. & age !=. & hhsize !=. & tenure !=. & msa !=. & educyr !=. ///
& attsch_ever !=. & native !=. & lit !=. & gender !=.) | (occupation_unemp != . & age !=. & hhsize !=. & msa !=. & educyr !=. & attsch_ever !=. & native !=. & lit !=. & gender !=.)

********************************************************************************
********************************************************************************

*** Locals for controls


local occup occupation
local base_controls "msa year"
local controls "age age2 hhsize lit native attsch_ever educyr educyr2 i.marstat i.dec_pcfaminc"

********************************************************************************
********************************************************************************
********************************************************************************

** Create indicators for level of education

gen primary = educlv>=2
label var primary "Complete primary school (share)"

gen secondary = educlv>=4
label var secondary "Complete secondary school (share)"

gen tertiary = educlv==6 | educlv==8
label var tertiary "Complete higher education (share)"

** Create indicators for internal and foreign migrant

gen migrint = (native==1 & migrant==1)
label var migrint "Share internal migrant"

gen migrfor = (native==0 & migrant==1)
label var migrfor "Share foreign migrant"

** Create married indicator

gen married = marstat == 2
label var married "Share married"


********************************************************************************
********************************************************************************
********************************************************************************

* Run regression for pension contribution to restrict the sample to use

qui reghdfe cont_pens domwk_all treat_dwall `controls' if ${ctrl_group} == 1 & unemployed == 0, absorb(`base_controls' `occup') vce(cluster msa)
gen sample_reg = 1 if e(sample)

* Create the summary statistics table

* Domestic workers

estpost sum age migrint migrfor married hhsize lit attsch_ever primary secondary tertiary educyr hours_mjob inc_mjob_base08 wagehr_mjob_base08 tenure cont_pens cont_health health_ins ///
if treat == 0 & domwk == 1 & sample_reg == 1
estimates store Domestic_pre

** Female Service workers

estpost sum age migrint migrfor married hhsize lit attsch_ever primary secondary tertiary educyr hours_mjob inc_mjob_base08 wagehr_mjob_base08 tenure cont_pens cont_health health_ins ///
if treat == 0 & domwk == 0 & ${ctrl_group} == 1 & sample_reg == 1
estimates store Female_Service_pre

estpost ttest age migrint migrfor married hhsize lit attsch_ever primary secondary tertiary educyr hours_mjob inc_mjob_base08 wagehr_mjob_base08 tenure cont_pens cont_health health_ins ///
if treat == 0 & ${ctrl_group} == 1 & sample_reg == 1, by(domwk) unequal
estimates store Female_Service_test

esttab Domestic_pre Female_Service_pre Female_Service_test using "$tables/Table 1", replace csv mtitle("Domestic Workers" "Low-wage service workers" "Difference") ///
cell("mean(label(Mean) pattern(1 1 0) fmt(2)) b(star fmt(3) pattern(0 0 1))") label nonum f collabels(none)